<template>
  <simple-layout title=" ">
    <div class="forget-top">
      修改支付密码
    </div>

    <div class="mui-toast-container">
      <div class="mui-toast-message">

      </div>
    </div>

    <form class="ab-input-group">　
      <div class="ab-input-row">
        <span class="login-forget" @click="sendCode"><span :class="[numCode !== '发送验证码'? 'blue' : '']">{{ numCode }}{{numCode !== '发送验证码'? 's' : ''}}</span> {{numCode !== '发送验证码' ? '后重发' :''}}</span>
        <input type="text" class="ab-input ab-input-clear" placeholder="请输入手机号码" v-model="phone">
      </div>
      <div class="ab-input-row">
        <input type="text" class="ab-input ab-input-clear" placeholder="请输入手机验证码" v-model="code">
      </div>
      <div class="ab-input-row">
        <input type="password" class="ab-input ab-input-password mui-input-password" placeholder="请输入新支付密码" v-model="password">
      </div>
      <div class="ab-button-row">
        <button type="button" class="ab-btn ab-btn-primary"  @click="submitForget()">提 交</button>
      </div>
    </form>

  </simple-layout>
</template>


<script>
  import AuthService from '../../service/auth';
  import SimpleLayout from '../../components/SimpleLayout';

  export default {
    name: "Login",
    components: {
      //someComponent
      SimpleLayout
    },
    props: {},
    data() {
      return {
        msg: "Hello Vue.js",
        phone: '',
        code: '',
        password: '',
        numCode: '发送验证码',
      }
    },
    computed: {},
    watch: {},
    mounted: function () {
    },
    methods: {
      // 点击发送验证码
      sendCode() {
        if (this.numCode !== '发送验证码') {
          return
        }
        const params = {
          phone: this.phone,
        }
        AuthService.sendCodeForResetPayPwd(params).then((res) => {
          if (res.status == 200) {
            this.numCode = 60;
            this.validateCodeClock = setInterval(() => {
              this.numCode = this.numCode - 1;
              if (this.numCode <= 0) {
                clearInterval(this.validateCodeClock);
                this.numCode = '发送验证码';
              }
            }, 1000);
          }
        })
      },
      // 点击提交
      submitForget() {
        const params = {
          mobile: this.phone,
          captcha:this.code,
          newPwd: this.$md5(this.password)
        }
        AuthService.modifyPwdWithoutMd5(params).then((res) => {
          if (res.status == 200) {
            mui.confirm('','设置成功',new Array('关闭'),(e)=>{
              this.$router.push({ name:"UserInfo" });
            });
          }
          else if(res.status == '001020'){
            mui.confirm('','验证码错误',new Array('关闭'));
          }
        })
      }
    }
  }
</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .ab-input-group {
    margin-top: 60px;
  }

  .ab-input-row {
    margin-top: 10px;
    position: relative;
  }

  .ab-input {
    background: transparent;
    width: 300px;
    margin:10px;
    border-left: none;
    border-right: none;
    border-top: none;
  }

  .ab-btn-primary {
    margin-top: 50px;
    width: 300px;
    height: 40px;
    color: white;
    background: rgb(130, 130, 244);
    border-radius: 15px;
    border: 0px;
  }

  .ab-btn.ab-btn-primary{
    font-size: 20px;
  }

  input::-webkit-input-placeholder { /* WebKit browsers */
    color: #ccc;
  }

  input:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
    color: #ccc;
  }

  input::-moz-placeholder { /* Mozilla Firefox 19+ */
    color: #ccc;
  }

  input:-ms-input-placeholder { /* Internet Explorer 10+ */
    color: #ccc;
  }


  .forget-top {
    width: 300px;
    text-align: initial;
    margin: 6rem auto 0;
    font-size: 24px;
    font-weight: bolder;
  }
  .blue{
    color: blue;
  }
  .mui-popup.mui-popup-in{
    border-radius: 0;
  }
  .login-forget{
    font-size: 16px;
    position: absolute;
    right: 13%;
    top: 34%;
    color: black;
  }
</style>
